package com.goma.test;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

import org.apache.log4j.Logger;

public class BroadCastReceive {
    private static final Logger logger = Logger.getLogger(BroadCastReceive.class);
    public static void main(String[] args) {
        try {
            DatagramSocket ds = new DatagramSocket(3001);// 创建接收数据报套接字并将其绑定到本地主机上的指定端口
            byte[] buf = new byte[1024];
            DatagramPacket dp = new DatagramPacket(buf, buf.length);
            while (true) {

                ds.receive(dp);
                logger.info(new String(buf));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
